﻿create PROCEDURE Sync.SP_LoanSocialResearch_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[LoanSocialResearchID],
		g.[LoanID],g.[SocialResearchDate],g.[FamilyNumbers],g.[IncomeAmount],g.[Notes],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[LoanSocialResearch] g RIGHT JOIN Sync.LoanSocialResearch_Tracking t  
    ON t.LoanSocialResearchID = g.LoanSocialResearchID 
    join [CustomerLoans] cl
		on g.LoanID = cl.LoanID
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
	AND ((@FilterdColumn IS NULL) OR (cl.CommitteeID = @FilterdColumn))
    END














